﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Dsv
    Inherits System.Web.Services.WebService
    <WebMethod()> _
    Public Function MD5(chuoi As String) As String
        Return pAnother.MD5(chuoi)
    End Function
    <WebMethod()> _
    Public Function SQL2DS(Query As String) As Data.DataSet
        Dim DS As New pDataFunction
        Return DS.SQL2DS(Query)
    End Function
    <WebMethod()> _
    Public Function SQL2TB(Query As String) As Data.DataTable
        Dim DS As New pDataFunction
        Dim TB As New Data.DataTable
        TB.TableName = "TB"
        TB = DS.SQL2TAB(Query)
        Return TB
    End Function
    <WebMethod()> _
    Public Function GetFile(ByVal FileName As String) As String
        Return Server.MapPath(FileName)
    End Function
    <WebMethod()> _
    Public Function UploadFile(ByVal f As Byte(), ByVal fileName As String) As String
        Try
            Dim ms As New IO.MemoryStream(f)
            Dim fs As New IO.FileStream(Server.MapPath("") & fileName, System.IO.FileMode.CreateNew)
            ms.WriteTo(fs)
            ms.Close()
            fs.Close()
            fs.Dispose()
            Return "Tệp " & fileName & " đã được tải lên!"
        Catch ex As Exception
            Return "Không tải được do lỗi:" & vbCrLf & ex.Message.ToString()
        End Try
    End Function
    <WebMethod()> _
    Public Function CreateFolder(ByVal folder As String) As String
        Try
            System.IO.Directory.CreateDirectory(Server.MapPath("") & "\" & folder)
            Return "Thư mục " & Server.MapPath("") & "\" & folder & " đã được tạo!"
        Catch ex As Exception
            Return "Không tạo được do lỗi:" & vbCrLf & ex.Message.ToString()
        End Try
    End Function
End Class